/// 和用户相关的业务
part of pda.service;

class User {
  String id;
  String code;
  String name;
  String password;

  User({this.id, this.code, this.name, this.password});

  factory User.fromJson(Map<String, dynamic> map) {
    return User(
      id: map['id'],
      code: map['code'],
      name: map['name'],
      password: map['password'],
    );
  }

  Future<User> login() async {
    var user = await SqliteHelper.instance.fetch(Tables.pda_user, id);
    if (user == null || user['password'] != password) {
      return null;
    }
    return User.fromJson(user);
  }

  static String insertSql() {
    return '''insert into pda_user (
      id,
      code,
      name,
      password
    ) values (
      ?,
      ?,
      ?,
      ?
    )
    ''';
  }

  List insertSqlArgs() {
    return [id, code, name, password];
  }
}
